package com.ita.acmsystem.merchant.servlet.mock;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ita.acmsystem.merchant.entity.Foods;
import com.ita.acmsystem.merchant.entity.mock.ProtocalMock;
import com.ita.acmsystem.merchant.util.SimpleJsonUtil;

/**
 * Servlet implementation class ContentServletMock
 */
public class ContentServletMock extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ContentServletMock() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		showAll(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		showAll(request, response);
	}

	private void showAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		List<Foods> foods = new ArrayList<Foods>();
		
		Foods food = new Foods();
		food.setFoodId(UUID.randomUUID().toString());
		food.setFoodName("RICE");
		food.setFoodPrice("$1.0");
		food.setFoodPic("rice.jpg");
		food.setFoodFoodTypeId("1");
		food.setMerchantId(UUID.randomUUID().toString());
		foods.add(food);
		
		food.setFoodId(UUID.randomUUID().toString());
		foods.add(food);
		
		food.setFoodId(UUID.randomUUID().toString());
		foods.add(food);
		
		food.setFoodId(UUID.randomUUID().toString());
		foods.add(food);
		
		food.setFoodId(UUID.randomUUID().toString());
		foods.add(food);
		
		ProtocalMock protocal = new ProtocalMock();
		protocal.setStatus("success");
		protocal.setMessage("");
		protocal.setData(foods);
		
		PrintWriter writer = response.getWriter();
		writer.write(SimpleJsonUtil.format(protocal));
		writer.close();
	}
}
